#include "LearnSocket.h"
#include <iostream>

using namespace std;

void showSocketDemoMenu()
{
	cout << "**********************************************************" << endl;
	cout << "Socket 学习案例菜单:" << endl;
	cout << "输入对应选项索引号并回车进入：" << endl;
	cout << "  1. 案例一：最简服务器（流式tcp）" << endl;
	cout << "  2. 案例一：最简客户端（流式tcp）" << endl;
	cout << "  3. 案例二：最简多线程处理并发服务器（流式tcp）" << endl;
	cout << "  4. 案例三：基于线程池处理并发服务器（流式tcp）" << endl;
	cout << "  5. 案例四：TCP粘包问题及解决演示（服务器端）" << endl;
	cout << "  6. 案例四：TCP粘包问题及解决演示（客户端）" << endl;
	cout << "  7. 案例五：IO多路转接（复用）之select方案" << endl;
	cout << "  8. 案例六：IO多路转接（复用）之poll方案" << endl;
	cout << "  9. 案例七：IO多路转接（复用）之epoll方案（linux 平台的）" << endl;
	cout << "  a. 案例八：IO多路转接（复用）之kqueue方案（apple 平台的 epoll 替代）" << endl;
	cout << "  b. 案例九：IO多路转接（复用）之IOCP方案（windows 平台的 epoll 替代）" << endl;
	cout << "  Q. 退出；" << endl;
	cout << "**********************************************************" << endl;
	cout << "请输入:" << endl;
}

void gotoSocketDemoMenu()
{
	char commond;
	while (showSocketDemoMenu(), cin >> commond, 'q' != tolower(commond)) {
		switch (tolower(commond)) {
		case '1':
			socketSimpleTcpServer();
			break;
		case '2':
			socketSimpleTcpClient();
			break;
		case '3':
			socketConcurrentTcpServer();
			break;
		case '4':
			socketConcurrentPoolServer();
			break;
		case '5':
			socketStickyPacketServiceDemo();
			break;
		case '6':
			socketStickyPacketClientDemo();
			break;
		case '7':
			socketSelectDemo();
			break;
		case '8':
			socketPollDemo();
			break;
		case '9':
			socketEpollDemo();
			break;
		case 'a':
			socketKqueueDemo();
			break;
		case 'b':
			socketIocpDemo();
			break;
		}
	}
}